#include "server.h"

void destroy(char* buf)
{
	char path[PATH_LEN] = {};
	sprintf(path,"%s%s",ACC_PATH,ctos.acc.bank);

	//判断银行卡号是否正确
	if(0 != access(path,F_OK))
	{
		sprintf(buf,"N:卡号不存在，请检查！");
		return;
	}

	int fd = open(path,O_RDWR);
	if(0 > fd)
	{
		error("open");
		sprintf(buf,"N:服务器正在升级，销户失败!");
		return;
	}

	Acc acc = {};
	read(fd,&acc,sizeof(Acc));
	close(fd);

	if(strcmp(acc.IdCard,ctos.acc.IdCard))
	{
		sprintf(buf,"N:身份证号不正确，销户失败!");
		return;
	}

	if(strcmp(acc.password,ctos.acc.password))
	{
		sprintf(buf,"N:密码不正确，销户失败!");
		return;
	}

	if(remove(path))
	{
		error("remove");
		sprintf(buf,"N:服务器正在升级，销户失败!");
		return;
	}

	sprintf(buf,"Y:销户成功，期待再次使用!");
}